<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="thx" uri="/thx-tags"%>
<style>
.form-horizontal .form-group {
	margin-right: 0px;
	margin-left: 0px;
}
</style>


<form id="user-form" name="ui-adminlte-form" class="form-horizontal"
	data-toggle="validator" role="form" method="post"
	container = "div.right"
	action="${pageContext.request.contextPath}/information/information!save.action"
	forward-action="${pageContext.request.contextPath}/information/information!list.action?columnId=${columnId}">
	<s:token></s:token>
	<input type="hidden" name="id" value="${entity.infoId}"/>
	<input type="hidden" name="message" value="${message}" />
	<input type="hidden" name='entity.infoId' value="${entity.infoId}">
	
	<div id="commons">
		<div class="row">
            <div class="col-md-12">
                <div class="form-group">
                 	<label>栏目名称</label>
                 	<c:choose>
                 	<c:when test="${empty columnId}">
						<select class="form-control required" name="entity.columnId" id="entity.columnId">
							<c:forEach items="${dicInfoColumns}" var="icolumn">
							<option value="${icolumn.columnId}">${icolumn.columnName}</option>
	                 		</c:forEach>						
						</select>                 	
                 	</c:when>
                 	<c:otherwise>
                 		<input type="text" name="" class="form-control" readonly="true" value="${belongInfoColumn.columnName}">
                 		<input type="hidden" name='entity.columnId' value="${columnId}">
                 	</c:otherwise>
					</c:choose>
                </div>
            </div>
        </div>
		<div class="row">
            <div class="col-md-12">
                <div class="form-group">
                 	<label>标题</label> 
					<input type="text" name="entity.infoTitle"class="form-control required" placeholder="请输入标题" value="${entity.infoTitle}">
                </div>
            </div>
        </div>
		<div class="row">
            <div class="col-md-12">
                <div class="form-group">
                 	<label>内容</label> 
                 	<textarea name="entity.infoContent" class="form-control required">${entity.infoContent}</textarea> 
                </div>
            </div>
        </div>
		<div class="row">
            <div class="col-md-12">
                <div class="form-group">
                 	<label>按人员发布</label> 
					<input type="text" name="entity.perBound"class="form-control" placeholder="" value="${entity.perBound}">
                </div>
            </div>
        </div>
		<div class="row">
            <div class="col-md-12">
                <div class="form-group">
                 	<label>按部门发布</label> 
					<input type="text" name="entity.deptBound"class="form-control" placeholder="" value="${entity.deptBound}">
                </div>
            </div>
        </div>
		<div class="row">
            <div class="col-md-12">
                <div class="form-group">
                 	<label>按角色发布</label> 
					<input type="text" name="entity.roleBound"class="form-control" placeholder="" value="${entity.roleBound}">
                </div>
            </div>
        </div>
		<div class="row">
            <div class="col-md-12">
                <div class="form-group">
                 	<label>其他</label> 
					<input type="checkbox" name="entity.canComment" value="1" <c:if test="${entity.canComment=='1'}">checked</c:if>/>可以评论
                </div>
            </div>
        </div>        
		<div class="row">
            <div class="col-md-12">
                <div>
 					<label>投票设置</label>
                    <input type="checkbox" name="entity.canVote" id="canVoteSelect" value="1" <c:if test="${entity.canVote=='1'}">checked</c:if>/>可以投票        
                </div>
            </div>
        </div>
        <div id="voteset" style="display: none">
			<div class="row">
	            <div class="col-md-12">
	                <div>
	 					<label>项目形式</label>
	                    <input type="radio" name="entity.itemForm" value="0" <c:if test="${entity.itemForm=='0'}">checked</c:if>/>单选
	                    <input type="radio" name="entity.itemForm" value="1" <c:if test="${entity.itemForm=='1'}">checked</c:if>/>多选        
	                </div>
	            </div>
	        </div>		           
			<div class="row">
	            <div class="col-md-12">
	                <div>
	 					<label>投票形式</label>
	                    <input type="radio" name="entity.voteMode" value="0" <c:if test="${entity.voteMode=='0'}">checked</c:if>/>实名模式 (所有人都可以看到投票结果和投票人姓名)
	                    <input type="radio" name="entity.voteMode" value="1" <c:if test="${entity.voteMode=='1'}">checked</c:if>/>匿名模式(所有人都只能看到投票结果而不能看到投票人姓名)
	                    <input type="radio" name="entity.voteMode" value="2" <c:if test="${entity.voteMode=='2'}">checked</c:if>/>管理员模式(只有管理员才能查看到投票结果和投票人姓名)
	                </div>
	            </div>
	        </div>        
			<div class="row">
				<table id="listDicvs" class="table table-bordered table-hover">
					<thead>
						<tr>
							<th style="width:80%">选项名称</th>
							<th style="width:20%">操作</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${view.infoVoteItemLog}" var="voteItem" varStatus="row">
							<tr id="${voteItem.infoVoteItem.voteItemId}">
								<td style="display: none;">
									<input type="hidden" name="dicvIds" value="${voteItem.infoVoteItem.voteItemId}" />
								</td>
								<td class="form-group">
									<div class="col-sm-9">
										<input name="dicvTexts" id="textID${row.count}" value="${voteItem.infoVoteItem.optionName}"
											class="dicv-name form-control required notEqualToGroup" type="text" />
									</div>
								</td>
								<td>
									<button type="button"
											title="删除"
											data-toggle="tooltip"
											data-placement="bottom"
											data-id="${voteItem.infoVoteItem.voteItemId}"
											class="btn btn-default btn-sm btn-del">
											<i class="fa fa-trash"></i>
									</button>
								</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
				<div>
					<button type="button" class="btn btn-primary btn-add-dicv" style="margin:10px 0px 0px 10px">
						添加投票选项
					</button>
				</div>
			</div>
		</div>
	</div>
</form>
<script>
require(['jquery','form','util', 'dialog','iCheck' ], function($,form,util ,dialog) {
	form.init();
	// 控制投票设置区域缺省显示属性
	var canVote = "${entity.canVote}";
	$(function() {
		if(canVote == "1"){
			$("#voteset").css('display','block');
			$("#canVoteSelect").iCheck('check');
		}else{
			$("#voteset").css('display','none');
		}
	});
	$('input[type="radio"]').iCheck({
		checkboxClass : 'icheckbox_square-blue',
		radioClass : 'iradio_square-blue'
	});
	$('input[type="checkbox"]').iCheck({
		checkboxClass : 'icheckbox_square-blue',
		radioClass : 'iradio_square-blue'
	});
	$("#canVoteSelect").on("ifChecked",function(event) {
		$("#voteset").css('display','block');
	});
	$("#canVoteSelect").on("ifUnchecked",function(event) {
		$("#voteset").css('display','none');
	});
	
	//删除字典值
	function delDom(obj){
		var id = $(obj).attr("data-id");
		if(id == ''){//删除手动添加的dom
			$(obj.parentNode.parentNode).remove();
		}else{//删除数据库已存在的字典值
			var callBack = function(id, modal) {
				var url = '${pageContext.request.contextPath }/information/information!deleteVoteItem.action?id='+id;
				$.post(url, function(msg){
					modal.modal('hide');
					msg = util.strToObj(msg);
					dialog.alert(msg.desc);
					if(msg.code == "success"){
						$(obj.parentNode.parentNode).remove();
					}
				});
			};
			dialog.confirm(id, callBack, 'btn-del');
		}
	}
	
	//给当前页面的删除按钮绑定事件
	$(".btn-del").bind("click", function(){ delDom(this); });
	
	//添加字典值栏位
	function addDicv() {
		var dicvTextsId = 'textID1';
		if ($("#listDicvs").find("tr").length != 1) {
			var tr = $("#listDicvs").find("tr").last();
			var lastDicvTextsId = tr.find("input[name='dicvTexts']").attr("id");
			dicvTextsId = 'textID' + (lastDicvTextsId.substring(6)-0+1);
		}
		$("#listDicvs").find("tbody").append(
				"<tr>"
						+ "<td style='display:none'>"
						+ "<input type='hidden' name='dicvIds'/>"
						+ "</td>"
						+ "<td class='form-group'>"
						+ "<div class='col-sm-9'>"
						+ "<input name='dicvTexts' id='" + dicvTextsId + "' class='dicv-name form-control required notEqualToGroup' type='text' />"
						+ "</div>"
						+ "</td>"
						+ "<td>"
						+ "<button type='button' title='删除' data-toggle='tooltip' data-placement='bottom' data-id='' class='btn btn-default btn-sm btn-del'><i class='fa fa-trash'></i></button>"
						+ "</td>"
						+"</tr>");
		
		$(".btn-del").last().bind("click", function(){ delDom(this); });
	}
	
	//绑定添加事件
	$(".btn-add-dicv").click(function(){ addDicv(); });
});
</script>

